<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/25
 * Time: 9:46
 */
namespace app\index\logic;
 use app\index\model\Manager;
 use think\facade\Session;
 class Login extends BaseLogic
{
    public function __construct(array $data = [])
    {
        parent::__construct($data);
    }

     /**
      * 登录操作
      * @param $param
      * @return array
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
    public function getLogin($param){
         $user =Manager::where('uname',$param['uname'])->find();
         if(!$user){
          return $this->returnMsg('1002','无此帐号');
        }
        if(passwd($param['pwd'])==$user['pwd']){
                Session::set('u_id',$user['id']);
                Session::set('shop_id',$user['sid']);
                if($param['remember']==1){//密码保存
                    cookie('remember', $param['remember'], 24 * 3600 * 90);
                }else{
                    cookie('remember',null);
                }
//                $data=['token'=>md5(passwd($param['pwd']).$user['id'].'token'),'u_id'=>$user['id'],'shop_id'=>$user['sid']];
                $data=['shop_id'=>$user['sid'],'u_id'=>$user['id']];
//               Manager::where('id',$user['id'])->setField('');
            return $this->returnMsg('1001','登录成功',$data);
        }else{
            return $this->returnMsg('1002','密码错误');
        }
    }
     /**
      * 退出操作
      * @return array
      */
    public function outLogin(){
        Session::set('u_id',null);
        Session::set('shop_id',null);
        return $this->returnMsg('1001','退出');
    }
}